classdef ET_GEN < handle
    
    properties
        
        % Eyelink switch
        
        EyeLink = 0
        
        % Screen properties
        
        scn = struct(...
            'mon',1, ... % 0 or 1
            'res',6, ...
            'w',1600, ... % 1 = 640x480; 3 = 1024x768
            'h',1200, ...
            'refresh_rate',60, ...% Refresh rate in Hz
            'wcm',40.8, ... % Width in centimenters
            'hcm',45.0, ... % Height in centimenter
            'dist',60) % Distance from scn to subject
        
        % Configuration of the Eyelink
        
        eyelink_cfg = struct('screen_phys_coords',[], ...
            'screen_pixel_coords', [], ...
            'screen_distance',[])        
        
        % Date for time stamp
        
        date
        
        % Experiment information
        
        exp_par = struct()
        
        % Assumes a block - trial design
               
        blocks
        trials
        
        num_blocks
        num_trials
        
        % Pointer of the screen
        
        scn_pointer
        
    end
    
    methods
        
        
        function self = ET()
            self.date = clock;                        
        end
        
        function runScreen(self)
            % Runs the screen. Because it depends on the GM in this case it
            % is only a place holder
        end
        
        function start_GM(self)
            % Initializes the graphical motor, i.e., cogent or PTB. It is
            % only a place holder.
        end
        
        function prepareBlocks(self)
            % Initializes the block. This is only a place holder.
        end        
        
        function prepareTrials(self)
            % Initializes the trials. This is only a place holder.
        end
        
        function trialTransition(self)
            % Specifies the transition from one trial to other. In this
            % case it is a place holder.
        end
        
        
        function startDialog(self)
            % Dialog that starts before running the experiment.

            prac = input('Practice(y/n)? ','s');

            if prac == 'y';
                self.exp_par.Sbj = 0; self.exp_par.Exp = 0;

            else
                self.exp_par.sbj = input('Subject number? ');
                self.exp_par.exp = input('Experiment number? ');
                while 1
                    tmp = input('Connect to EyeLink? (y/n)');
                    if strcmp(tmp,'y')
                        self.EyeLink = 1;
                    elseif strmp(tmp,'n')
                        self.EyeLink = 0;
                    else
                        fprintf(1,'Option not recognize.\n');
                        continue
                    end
                    break
                end
            end
            
        end
        
        function prepareEyelink(self)
            
            if ~self.EyeLink
               warning('Setup of Eyelink aborted. Check if Eyelink option is on.')
               return
            end
            
            % EYETRACKER SETUP            
            
            Eyelink('Command', sprinft('screen_phys_coords = %f, %f, %f, %f',...
                self.eyelink_cfg.screen_phys_coords));
            % in millimetres
            Eyelink('Command',...
                sprintf('screen_pixel_coords = %d, %d, %d, %d', ...
                round(self.eyelink_cfg.screen_pixel_coords)));
            % screen resolution
            Eyelink('Command', sprintf('screen_distance = %f, %f',...
                self.eyelink_cfg.distance));
            
        end
        
    end
end